
let webpack = require('webpack');
let modules = {};
let ExtractTextPlugin = require('extract-text-webpack-plugin');
let extractCSS = new ExtractTextPlugin('[name].css');
let extractLESS = new ExtractTextPlugin({
    filename: '[name].css'
});
let SpritesmithPlugin = require('webpack-spritesmith');
let path = require('path');
let spritesmithPlugin = new SpritesmithPlugin({
    src: {
        cwd: path.resolve(__dirname, '../static/img'),
        glob: '*.png' //配置限制，暂时只匹配png
    },
    target: {
        image: path.resolve(__dirname, '../pkg/img-sprites/sprite.png'),
        css: path.resolve(__dirname, '../pkg/img-sprites/sprite.less')
    },
    apiOptions: {
        cssImageRef: './sprite.png'
    },
    spritesmithOptions: {
        algorithm: 'top-down'
    }
});
let HtmlWebpackPlugin = require('html-webpack-plugin');
let htmlWebpackPlugin = new HtmlWebpackPlugin({
    title: 'index',
    filename: 'page/index/index.html',
    template: 'page/index/index.html',
    loader: "raw-loader",
    hash: true,
});

modules.getTheOption = {
    rules: [
        {
            test: /\.ts$/,
            exclude: /(node_modules|webpackConf|tsconfig|package-lock)/,
            use: 'ts-loader'
        },{
            test: /\.less$/,
            exclude: /(node_modules)/,
            use: extractLESS.extract({
                use: [{
                    loader: 'css-loader',
                    options: {
                        minimize: true
                    }
                }, {
                    loader: 'less-loader'
                }],
                fallback: 'style-loader'
            })
        }
    ]
};

modules.pluginArray = [
    extractCSS,
    extractLESS,
    spritesmithPlugin,
    htmlWebpackPlugin
];

module.exports = modules;